# -*- coding: utf-8 -*-
"""
Created on Tue Dec 24 08:38:48 2013

@author: Casa
"""
from scipy.weave import  ext_tools,inline
import numpy as np

def __build__():
    mod = ext_tools.ext_module('cfunc')
    with open('__CFUNCTION__.cpp') as cfile:
        support_code=cfile.read()
    #function:find_max_vec(subvec)
    block_size=12
    encode_num=32
    data=np.empty(0,np.int64)
    code='''
    return_val=_OSHC(data,Ndata[0],block_size,encode_num);
    '''
    f = ext_tools.ext_function('OSHC',code,['data','block_size','encode_num'])    
    f.customize.add_support_code(support_code)
    mod.add_function(f)
    #switch vector and integer
    code='''
    return_val=_vec2int(data,Ndata);
    '''
    data=np.empty(0,np.int)
    f = ext_tools.ext_function('v2i',code,['data'])    
    mod.add_function(f)
    code='''
    return_val=_int2vec(data,Ndata[0],block_size);
    '''
    data=np.empty(0,np.int64)
    f = ext_tools.ext_function('i2v',code,['data','block_size'])    
    mod.add_function(f)
    #FDR
    data=np.empty(0,np.int)
    code='''
    int size=1;
    for(int i=0;i<Ddata;i++)
        size*=Ndata[i];
    return_val=_FDR(data,size);
    '''
    f = ext_tools.ext_function('FDR',code,['data'])    
    mod.add_function(f)

    mod.compile(extra_compile_args=['-std=c++11','-include cmath'],
                extra_link_args=['-std=c++11'])
    
if __name__=="__main__":
    __build__()
    
